home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / hsrc_117.zip / EXPORT.C < prev    next >
Text File  |  1990-11-25  |  13KB  |  520 lines

  1. #include "msgg.h"
  2. #include "twindow.h"
  3. #include "keys.h"
  4. #include "headedit.h"
  5.  
  6.  
  7. /* Export messages */
  8.  
  9. void pascal make_file (void) {
  10.  
  11.     char xport[6];
  12.     char s[30];
  13.     word temp;
  14.     int returncode;
  15.     word tempmess;
  16.     struct ffblk f;
  17.     WINDOW *wnd;
  18.     FIELD *fld;
  19.  
  20. ReStart:
  21.         wnd=establish_window(1,maxy-7,6,80);
  22.         set_border(wnd,3);
  23.         set_title(wnd," Export message ");
  24.         set_colors(wnd,BORDER,7,0,0);
  25.         display_window(wnd);
  26.         wcursor(wnd,0,0);
  27.         wprintf(wnd," F10 to export or ESC to abort");
  28.         sprintf(xport,"%u",messno);
  29.         sprintf(s,"Export #(1-%u):",nomess);
  30.         wprompt(wnd,1,2,s);
  31.         wprompt(wnd,1,3,"Filename:");
  32.         fld=establish_field(wnd,21,2,msk5,xport,'N');
  33.         field_window(fld,"export#   ",40,6);
  34.         fld=establish_field(wnd,11,3,msk65,filenamer,'A');
  35.         field_window(fld,"exportname",40,7);
  36. Over:
  37.         prep_template(wnd);
  38.         returncode=data_entry(wnd);
  39.         if (returncode==ESC) {
  40.             delete_window(wnd);
  41.             return;
  42.         }
  43.         if (returncode!=F10) goto Over;
  44.         returncode=0;
  45.         rstrip(filenamer);
  46.         temp=(word)atol(xport);
  47.         if (!strlen(filenamer) || temp<1 || temp>nomess) {
  48.             error_message(" Invalid parameter ");
  49.             pause();
  50.             goto Over;
  51.         }
  52.         if (!findfirst(filenamer,&f,0)) {
  53.             any_message(" Exists...[O]verwrite [A]ppend [R]eEnter? [A] ");
  54. ReInput:
  55.             returncode=toupper(get_char());
  56.             if (returncode=='R' || returncode==ESC) {
  57.                 clear_message();
  58.                 goto Over;
  59.             }
  60.             if (returncode=='O') unlink(filenamer);
  61.             else if (returncode!='\r' && returncode!='A') {
  62.                 bell();
  63.                 goto ReInput;
  64.             }
  65.         }
  66.         clear_message();
  67.         tempmess=messno;
  68.         messno=temp;
  69.         get_mess(0);
  70.         delete_window(wnd);
  71.         wnd=establish_window(0,maxy-7,19,maxx);
  72.         set_border(wnd,3);
  73.         set_title(wnd," Exporting message ");
  74.         set_colors(wnd,BORDER,7,0,0);
  75.         display_window(wnd);
  76.         wcursor(wnd,0,0);
  77.         if (!export(filenamer,((currarea->attr & NET) || (currarea->attr & ALTERNATE)),TEXTFILE,"","",wnd)) {
  78.             delete_window(wnd);
  79.             goto ReStart;
  80.         }
  81.         clear_message();
  82.         delete_window(wnd);
  83.         messno=tempmess;
  84.         get_mess(0);
  85. }
  86.  
  87.  
  88. int pascal export (file,net,type,olddate,oldfrom,wndd)
  89.  
  90.  char *file;
  91.  char net;
  92.  char type;
  93.  char *olddate;
  94.  char *oldfrom;
  95.  void *wndd;
  96.  
  97. {
  98.  
  99.  static char text[124];
  100.  static char lines=0;
  101.  WINDOW *wnd;
  102.  register word x;
  103.  int pp;
  104.  char message[82];
  105.  char far *hold;
  106.  char *tempo;
  107.  char *p;
  108.  char width;
  109.  char noquote=0;
  110.  
  111.  wnd=(WINDOW *)wndd;
  112.  if(!strnicmp(file,"MSGTMP",6)) get_rid();
  113.  if(type != EDITIT) strcpy(to_domain,curaddress.domain);
  114.  *replyid=0;
  115.  if (type==TEXTFILE) width=78;
  116.  else if (type==PRINTIT) {
  117.     width=textwidth;
  118.     if (*olddate) lines=0;
  119.  }
  120.  else if (type==QUOTE || type==ECHO2NET) width=65;
  121.  else if (type==EDITIT) width=71;
  122.  
  123.  if(type!=NOQUOTE) {
  124.      if((pp=(_open(file,O_WRONLY | O_BINARY | O_DENYWRITE)))==-1)
  125.        if((pp=(creat(file,S_IWRITE)))==-1) {
  126.          sprintf(text,"Cannot open %s",file);
  127.          error_message(text);
  128.          pause();
  129.          return(0);
  130.      }
  131.  }
  132.  lseek(pp,0L,SEEK_END);
  133.  if (type==TEXTFILE || type==PRINTIT) {
  134.      if (type==PRINTIT) {
  135.         for (x=0;x<strlen(beforeheader);x++) {
  136.             if (beforeheader[x]=='\n') {
  137.                 lines++;
  138.                 ffprintf(pp,"\r\n");
  139.                 if(wnd)wprintf(wnd,"\n");
  140.             }
  141.             else {
  142.                 ffprintf(pp,"%c",beforeheader[x]);
  143.                 if(wnd)wprintf(wnd,"\n");
  144.             }
  145.             if(beforeheader[x]=='\xc') lines=0;
  146.         }
  147.      }
  148.      if (type==PRINTIT) if((lines+8)>(pagelength-bottommargin)) {
  149.         ffprintf(pp,"\xc\r\n");
  150.         if(wnd)wprintf(wnd,"\n <=-Page Break-=>\n\n");
  151.         lines=1;
  152.      }
  153.      if (type==PRINTIT) if (lines<topmargin) {
  154.         for (x=lines;x<topmargin;x++) {
  155.             ffprintf(pp,"\r\n");
  156.             if(wnd)wprintf(wnd,"\n");
  157.         }
  158.         lines=topmargin;
  159.      }
  160.      if (type==PRINTIT) {
  161.         for (x=0;x<(word)leftmargin;x++) {
  162.             ffprintf(pp," ");
  163.             if(wnd)wprintf(wnd," ");
  164.         }
  165.      }
  166.      lines+=7;
  167.      ffprintf(pp,"Board #%u  *  Message #%u: ",areano,messno);
  168.      if(wnd)wprintf(wnd,"Board #%u  *  Message #%u: ",areano,messno);
  169.      if ((msg.attr & MSGPRIVATE)!=0) {
  170.         if(wnd)wprintf(wnd,"(Priv)");
  171.         ffprintf(pp,"(Priv)");
  172.      }
  173.      if ((msg.m_attr & MSGDELETED)!=0) {
  174.         ffprintf(pp,"(Del)");
  175.         if(wnd)wprintf(wnd,"(Del)");
  176.      }
  177.      if ((msg.attr & MSGCRASH)!=0) {
  178.         ffprintf(pp,"(CRASH)");
  179.         if(wnd)wprintf(wnd,"(CRASH");
  180.      }
  181.      if ((msg.attr & MSGKILL)!=0) {
  182.         ffprintf(pp,"(Kill)");
  183.         if(wnd)wprintf(wnd,"(Kill)");
  184.      }
  185.      if ((msg.attr & MSGSENT)!=0) {
  186.         ffprintf(pp,"(Sent)");
  187.         if(wnd)wprintf(wnd,"(Sent)");
  188.      }
  189.      if ((msg.attr & MSGFWD)!=0) {
  190.         ffprintf(pp,"(Fwd)");
  191.         if(wnd)wprintf(wnd,"(Fwd)");
  192.      }
  193.      if ((msg.attr & MSGREAD)!=0) {
  194.         ffprintf(pp,"(Recd)");
  195.         if(wnd)wprintf(wnd,"(Recd)");
  196.      }
  197.      if ((msg.attr & MSGRRQ)!=0) {
  198.         ffprintf(pp,"(Rec.Req)");
  199.         if(wnd)wprintf(wnd,"(Rec.Req)");
  200.      }
  201.      if ((msg.attr & MSGCPT)!=0) {
  202.         ffprintf(pp,"(Recpt)");
  203.         if(wnd)wprintf(wnd,"(Recpt)");
  204.      }
  205.      if ((msg.attr & MSGARQ)!=0) {
  206.         ffprintf(pp,"(Aud.Req)");
  207.         if(wnd)wprintf(wnd,"(Aud.Req)");
  208.      }
  209.      if ((msg.attr & MSGURQ)!=0) {
  210.         ffprintf(pp,"(Up.Req)");
  211.         if(wnd)wprintf(wnd,"(Up.Req)");
  212.      }
  213.      ffprintf(pp,"(Read %u times)\r\n",msg.times);
  214.      if(wnd)wprintf(wnd,"(Read %u times)\n",msg.times);
  215.  
  216.      if (type==PRINTIT) {
  217.         for (x=0;x<(word)leftmargin;x++) {
  218.             ffprintf(pp," ");
  219.             if(wnd)wprintf(wnd," ");
  220.          }
  221.      }
  222.      ffprintf(pp,"To:   %s",msg.to);
  223.      if(wnd)wprintfraw(wnd,"To:   %s",msg.to);
  224.      if ((net)!=0) {
  225.         ffprintf(pp," (%u/%u)",msg.dest_net,msg.dest);
  226.         if(wnd)wprintf(wnd," (%u/%u)",msg.dest_net,msg.dest);
  227.      }
  228.      ffprintf(pp,"\r\n");
  229.      if(wnd)wprintf(wnd,"\n");
  230.      if (type==PRINTIT) {
  231.         for (x=0;x<(word)leftmargin;x++) {
  232.             ffprintf(pp," ");
  233.             if(wnd)wprintf(wnd," ");
  234.         }
  235.      }
  236.      ffprintf(pp,"From: ");
  237.      if(wnd)wprintf(wnd,"From: ");
  238.      if ((msg.m_attr & MSGANON)!=0) {
  239.        ffprintf(pp,"*Anonymous* (%s)",msg.from);
  240.        if(wnd)wprintfraw(wnd,"*Anonymous* (%s)",msg.from);
  241.      }
  242.      else {
  243.         ffprintf(pp,"%s",msg.from);
  244.         if(wnd)wprintfraw(wnd,"%s",msg.from);
  245.      }
  246.      if (net) {
  247.         ffprintf(pp," (%u/%u)",msg.orig_net,msg.orig);
  248.         if(wnd)wprintf(wnd,"(%u/%u)",msg.orig_net,msg.orig);
  249.      }
  250.      ffprintf(pp,"\r\n");
  251.      if(wnd)wprintf(wnd,"\n");
  252.      if (type==PRINTIT) {
  253.         for (x=0;x<(word)leftmargin;x++) {
  254.             ffprintf(pp," ");
  255.             if(wnd)wprintf(wnd," ");
  256.         }
  257.      }
  258.      ffprintf(pp,"On:   ");
  259.      if(wnd)wprintf(wnd,"On:   ");
  260.  
  261.      if ((msg.m_attr & MSGANON)!=0) {
  262.        ffprintf(pp,"%9.9s",msg.date);
  263.        if(wnd)wprintfraw(wnd,"%9.9s",msg.date);
  264.      }
  265.      else {
  266.         ffprintf(pp,"%s",msg.date);
  267.         if(wnd)wprintfraw(wnd,"%s",msg.date);
  268.      }
  269.      ffprintf(pp,"\r\n");
  270.      if(wnd)wprintf(wnd,"\n");
  271.      if (type==PRINTIT) {
  272.         for (x=0;x<(word)leftmargin;x++) {
  273.             ffprintf(pp," ");
  274.             if(wnd)wprintf(wnd," ");
  275.         }
  276.      }
  277.  
  278.      if ((msg.attr & MSGFILE)!=0) {
  279.         ffprintf(pp,"File: ");
  280.         if(wnd)wprintf(wnd,"File: ");
  281.      }
  282.      else if ((msg.attr & MSGFRQ)!=0) {
  283.         ffprintf(pp,"FReq: ");
  284.         if(wnd)wprintf(wnd,"FReq: ");
  285.      }
  286.      else if ((msg.attr & MSGURQ)!=0) {
  287.         ffprintf(pp,"UReq: ");
  288.         if(wnd)wprintf(wnd,"UReq: ");
  289.      }
  290.      else {
  291.         ffprintf(pp,"Subj: ");
  292.         if(wnd)wprintf(wnd,"Subj: ");
  293.      }
  294.      ffprintf(pp,"%s\r\n\r\n",msg.subj);
  295.      if(wnd)wprintfraw(wnd,"%s\n\n",msg.subj);
  296.      if (type==PRINTIT) {
  297.         for (x=0;x<strlen(afterheader);x++) {
  298.             if (afterheader[x]=='\n') {
  299.                 lines++;
  300.                 ffprintf(pp,"\r\n");
  301.                 if(wnd)wprintf(wnd,"\n");
  302.             }
  303.             else {
  304.                 ffprintf(pp,"%c",afterheader[x]);
  305.                 if(wnd)wprintfraw(wnd,"%c",afterheader[x]);
  306.             }
  307.         }
  308.      }
  309.  }
  310.  
  311.  if (type==QUOTE || type==ECHO2NET) {
  312.  
  313.     if(editor) {
  314.         if (get_qstring(quotestring)==NULL) {
  315.             _close(pp);
  316.             get_rid();
  317.             return 0;
  318.         }
  319.     }
  320.     else *quotestring=0;
  321.  
  322.     if(!strcmp(quotestring,"NOQUOTE")) {
  323.         *quotestring=0;
  324.         noquote=1;
  325.     }
  326.     if(type==ECHO2NET) {
  327.         ffprintf(pp,"  *Replying to msg in %s\r\n",currarea->name);
  328.